package com.itgone.model.impl;

import com.alibaba.fastjson.JSON;
import com.itgone.bean.User;
import com.itgone.common.MallAPI.UserAPI;
import com.itgone.model.IUserModel;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.Callback;

import okhttp3.MediaType;

import static com.itgone.common.Const.KEY_PASSWORD;
import static com.itgone.common.Const.KEY_USERNAME;

public class UserModelImpl implements IUserModel {
    @Override
    public void login(String username, String password, Callback callback) {
        OkHttpUtils
                .post()
                .url(UserAPI.LOGIN)
                .addParams(KEY_USERNAME, username)
                .addParams(KEY_PASSWORD, password)
                .build()
                .execute(callback);
    }

    @Override
    public void register(User user, Callback callback) {
        OkHttpUtils
                .postString()
                .url(UserAPI.REGISTER)
                .content(JSON.toJSONString(user))
                .mediaType(MediaType.parse("application/json; charset=utf-8"))
                .build()
                .execute(callback);
    }
}
